package pers.li.controller.goods;

import pers.li.service.GoodsService;
import pers.li.model.Goods;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/goods/goodsCate.action")
public class GoodsCateController extends HttpServlet {
    private final GoodsService goodsService = new GoodsService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int childId = Integer.parseInt(req.getParameter("childid"));
        String sort = req.getParameter("sort");
        List<Goods> goods = null;
        if (sort == null) {
            goods = goodsService.getGoodsByCateId(childId);
        } else {
            assert false;
            goods = goodsService.getGoodsByCateIdSort(childId, sort);
        }
        req.setAttribute("goods", goods);
        req.getRequestDispatcher("goods_cate.jsp").forward(req, resp);
    }
}
